//
//  StartViewController.m
//  PlaneWar2
//
//  Created by HappyMilk 02 on 2017/4/6.
//  Copyright © 2017年 HappyMilk 02. All rights reserved.
//

#import "StartViewController.h"
#import "LoginHeader.h"
#import "PublicTool.h"

#import "StartModel.h"
#import "AFNetworking.h"


@interface StartViewController ()<UIAlertViewDelegate>

@property (weak, nonatomic) IBOutlet UIButton *btn_start;

@property (nonatomic ,strong) UIButton *logbtn;

@property (weak, nonatomic) IBOutlet UILabel *lab_title;
@property (weak, nonatomic) IBOutlet UILabel *lab_child;
@property (weak, nonatomic) IBOutlet UILabel *lab_bottem;

@property (nonatomic ,strong) UIView *zheView;


@end

@implementation StartViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

//    if([WeChatQQApi stander].m_loginType == LT_NONE){
//        
//    }else{
//        if ([WeChatQQApi stander].m_userUUID) {
//            [_btn_start setTitle:NSLocalizedStringFromTable(@"Start", @"InfoPlist", nil) forState:UIControlStateNormal];
//        }else{
//            [_btn_start setTitle:NSLocalizedStringFromTable(@"Log in", @"InfoPlist", nil) forState:UIControlStateNormal];
//        }
//    }
    
}
- (void)onAppInfoLoadedCB:(id)sender{
    
//    if([WeChatQQApi stander].m_loginType == LT_NONE){
//        
//    }else{
//        _logbtn.hidden = YES;
//        [_btn_start setTitle:NSLocalizedStringFromTable(@"Log in", @"InfoPlist", nil) forState:UIControlStateNormal];
//    }
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 9_0){
    if(buttonIndex == 0){
        NSURL * url = [NSURL URLWithString:@"prefs:root"];
        
        if([[UIApplication sharedApplication] canOpenURL:url]) {
            
            NSURL*url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];           [[UIApplication sharedApplication] openURL:url];
            
        }
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
    
    [StartModel registerSubclass];
    
    ADD_OBSERVER(self, @selector(onAppInfoLoadedCB:), NOTIFICATION_APP_INFO_LOADED, nil);
    // Do any additional setup after loading the view.
    _logbtn = [[UIButton alloc] initWithFrame:(CGRect){__kwidth/2+100,self.btn_start.frame.origin.y,80,50}];
    [_logbtn setTitle:NSLocalizedStringFromTable(@"Log in", @"InfoPlist", nil) forState:UIControlStateNormal];
    [_logbtn setTitleColor:HEXCOLOR(0x236EE7) forState:UIControlStateNormal];
    [_logbtn addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_logbtn];
    
    //[self registerModel];
    AVQuery *query = [StartModel query];
    [query findObjectsInBackgroundWithBlock:^(NSArray * _Nullable objects, NSError * _Nullable error) {
        if (objects.count > 0) {
            StartModel *model = objects[0];
            self.lab_title.text = model.title;
            self.lab_child.text = model.child;
            self.lab_bottem.text = model.bottem;
        }
    }];
    
    _zheView = [[UIView alloc] initWithFrame:self.view.bounds];
    _zheView.backgroundColor = [UIColor whiteColor];
    //[self.view addSubview:_zheView];
}
- (void)registerModel{
    
    StartModel *model = [[StartModel alloc] init];
    model.title = @"";
    model.child = @"";
    model.bottem = @"";
    [model saveInBackground];
}
- (IBAction)startGame:(UIButton *)sender {
//    if ([WeChatQQApi stander].m_userUUID) {
//        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//        UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"StoryViewController"];
//        vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//        [self presentViewController:vc animated:YES completion:nil];
//    }else{
//        if([WeChatQQApi stander].m_loginType == LT_NONE){
//            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//            UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"StoryViewController"];
//            vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//            [self presentViewController:vc animated:YES completion:nil];
//        }else{
//            [self login:nil];
//        }
//    }
    
}
- (void)login:(UIButton *)sender {
    
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"LoginViewController"];
    //vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentViewController:vc animated:YES completion:nil];
}
- (IBAction)useAgreement:(UIButton *)sender {
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
